package multimanipulators.finders;

import java.io.OutputStreamWriter;
import java.util.Iterator;
import java.util.List;

import be.djdb.UnConstruct;

import multimanipulators.interfaces.Converters;
import multimanipulators.interfaces.Finders;
@UnConstruct
public class Finder_keyword implements Finders{
	private static final long serialVersionUID = 436110908574313857L;
	private boolean ismatch;//wil zeggen wanneer er een positieve match is gevonden
	public List<Finders>finders;
	private Finders finder;
	private Converters converter;
	private int bufferclock;
	private char[] buffer;
	private int maxbuffer;
    public Finder_keyword(List<Finders> finders) {
		this.finders = finders;
	}
	@Override
	public void init() {
		// TODO Auto-generated method stub
	}
	@Override
	public boolean ismatchfound() {
		return ismatch;
	}
	@Override
	public boolean isnext(int read) {
		boolean ischarfound = false;
		for (Iterator<Finders> iter = finders.iterator(); iter.hasNext();) {//Generics No casting =>faster
            finder = iter.next();
            if(finder.isnext(read)){//equals char
                return true;
            }
            if(finder.ismatchfound()){
            	ismatch = finder.ismatchfound();
            	return true;
            }
        }
		return ischarfound;
	}
	public void setConverter(Converters converter) {
		this.converter= converter;
	}
	public void convert(char[] data, OutputStreamWriter doutstream) throws Exception {
		converter.manipulate(data, doutstream);
	}
	@Override
	public int compareTo(Object o) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int getusedbufferlength() {
		return bufferclock;
	}
}
